package gocomm

import (
	"fmt"
	"log"
	"math/rand"
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
	"time"
)

/*
获取当前 应用执行程序的目录
 /opt/gopath/src/github.com/prj/aaa/
 */
func GetCurrentPath() string {
	s, err := exec.LookPath(os.Args[0])
	if err != nil {
		panic(err)
	}
	log.Println(" LookPath:",s)
	s,err=filepath.Abs(s)
	log.Println(" Abs:",s)
	i := strings.LastIndex(s, string(os.PathSeparator))
	path := string(s[0 : i+1])
	return path
}


func GetErrorString(err error) string {
	if err!=nil{
		return err.Error()
	}else{
		return ""
	}
}


//随机一个flaot64 数字
func RandFloats(min, max float64) float64 {
	rand.Seed(time.Now().UnixNano())
	res := min + rand.Float64() * (max - min)
	value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", res), 64)

	return value
}
